<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻列表-分页显示</title>
<style type="text/css">    
/*新闻列表页面*/
.main a:hover{ text-decoration:none;}
.main a:link{ text-decoration:none;}
.main{ width:70%; float:left;}
.main li{ list-style:none; border-bottom:1px dotted #ccc; margin-bottom:20px; color:#66657D; }
.main .news_title{ font-size:22px; font-weight:bold; color:#3B3B3B;line-height:35px;}
.main .news_title a{color:#444;}
.main p{ margin:10px;;line-height:28px; font-size:14px;}
.main .news_content{text-indent:28px;}
.main .news_show{font-size:16px;}
.main .news_show a{color:#1685BD;font-size:14px; text-decoration:none;}
.main .news_label{ color:#393939;}
/*页码链接样式*/	
.page{font-size:12px;float:right;}
</style>
</head>
<?php
   require_once ('../common/news.dao.php');
   require_once ('../common/checkFormlib.php');
   require_once '../common/user.dao.php';
  //获取当前选择的页码
   $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
   //定义每页显示的记录行数
   $pagesize=2;
   $params=array();//保存url中参数列表
   if(isset($_GET['classid'])){
         $classid=test_input($_GET['classid']);
		 $max_page=maxpage_findNewsByClassid($classid,$pagesize);		
		 //获取当前选择的页码，并作容错处理
         $page = $page > $max_page ? $max_page : $page;
         $page = $page < 1 ? 1 : $page; 
		 $newslist=findNewsByClassid_page($classid,$page,$pagesize);
		 //将classid参数保存入数组变量$params		
		 $params['classid']=$classid;
   }else if(isset($_GET['keyword'])){//判断是否有关键字传入
        $keyword=test_input($_GET['keyword']);
	    $search_field=test_input($_GET['search_field']);
	    $max_page=maxpage_findNewsByName($keyword,$search_field,$pagesize); 
	    //获取当前选择的页码，并作容错处理
         $page = $page > $max_page ? $max_page : $page;
         $page = $page < 1 ? 1 : $page;
	   	 $newslist=findNewsByName_page($keyword,$page,$search_field,$pagesize);	
		 //将keyword和search_field参数保存入数组变量$params	
		 $params['keyword']=$keyword;
		 $params['search_field']=$search_field;		
   }else{
	     $max_page=maxpage_findNews($pagesize);
		 //获取当前选择的页码，并作容错处理
         $page = $page > $max_page ? $max_page : $page;
         $page = $page < 1 ? 1 : $page;                             
         $newslist=findNews_page($page,$pagesize);	  
   }   
   //组合分页链接的参数列表
   $param_str='?';
   if(!empty($params)){
	 foreach($params as $key=>$value){
	     $param_str=$param_str.$key.'='.$value.'&';	 
	 } 
   }  
 $page_html = "<a href='./newslist.php".$param_str."page=1'>首页&gt;&gt;</a>&nbsp;";
 $page_html .= "<a href='./newslist.php".$param_str."page=".(($page - 1) > 0 ? ($page - 1) : 1)."'>上一页&gt;&gt;</a>&nbsp;";
 $page_html .= "<a href='./newslist.php".$param_str."page=".(($page + 1) < $max_page ? ($page + 1) : $max_page)."'>下一页&gt;&gt;</a>&nbsp;";
 $page_html .= "<a href='./newslist.php".$param_str."page={$max_page}'>尾页&gt;&gt;</a>";   
?>
<body>
<div class="main">
	<ul>
    <?php  if(!empty($newslist)) { 
		 foreach($newslist as $row){
	?>
			<li><span class="news_title"><a href="newsdetail.php?newsid=<?php echo $row['newsid'];?>"><?php echo $row['title'];?></a></span>			
			<p class="news_content">
			<?php 
			$content = htmlspecialchars_decode(mb_substr(trim($row['content']),0,150,'utf-8')).'…… ……';
			echo $content;			
			?></p>
			<p class="news_show"><a href="newsdetail.php?newsid=<?php echo $row['newsid'];?>">点击查看全文&gt;&gt;</a></p>
			<p>发表时间：<span class="news_label"><?php echo $row['publishtime'];?> </span>　
			作者：<span class="news_label"><?php 
			 
			  $author=findUserById($row['uid']);
			  if(!empty($author)){
			  echo $author['uname'];}
			?> </span></p></li>
	<?php   }
	       
	     }else{?>
		   <li>暂无新闻数据！</li>
  <?php }?>		 
	</ul>
    <div class="page"><?php echo $page_html; ?></div>
</div>
</body>
</html>